<%--
  Created by IntelliJ IDEA.
  User: xiaoji
  Date: 2014/11/24
  Time: 14:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set value="${pageContext.request.contextPath}" var="path" scope="session"/>
<!DOCTYPE html>

<html>
<head>
    <title>订单报表</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="${path}/plugins/jquery-easyui-1.4.1/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="${path}/plugins/jquery-easyui-1.4.1/themes/icon.css">
    <script type="text/javascript" src="${path}/plugins/jquery-easyui-1.4.1/jquery.min.js"></script>
    <script type="text/javascript" src="${path}/plugins/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${path}/plugins/jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
    <script language="javascript" type="text/javascript" src="${path}/plugins/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript">
        $(function(){
            //查询
            $("#search_zp").click(function(){


                var currenttab =  $("#search_zp").attr("stab");
                $('#'+currenttab).datagrid('load',{
                    worksId:$("#worksId").val(),
                    beginTime:$("#worksBeginTime").val(),
                    endTime:$("#worksEndTime").val()

                });
                f_findCountOrderWorks();
            });

            f_findCountOrderWorks();

            $("#search_rw").click(function(){


                var currenttab =  $("#search_rw").attr("stab");
                $('#'+currenttab).datagrid('load',{
                    itemId:$("#itemId").val(),
                    beginTime:$("#finishBeginTime").val(),
                    endTime:$("#finishEndTime").val(),
                    itemOrderStatus:$("#itemOrderStatus").combobox("getValue"),
                    itemType:$("#itemType").combobox("getValue")
                });
               // f_findCountPlatformFinance();
            });
            $("#search_jshd").click(function(){


                var currenttab =  $("#search_jshd").attr("stab");
                $('#'+currenttab).datagrid('load',{
                    raceId:$("#raceId").val(),
                    beginTime:$("#finishBeginTime2").val(),
                    endTime:$("#finishEndTime2").val(),
                    raceOrderStatus:$("#raceOrderStatus").combobox("getValue")
                });

            });

            //切换
            $('#tabs').tabs({
                onSelect: function (title) {
                    if(title=="作品订单报表"){
                        $('#ttzpddbb').datagrid({
                            url:'${path}/orderReport/findOrderWorksReport.do',
                            method:'post',
                            queryParams:{
                                worksId:$("#worksId").val(),
                                beginTime:$("#worksBeginTime").val(),
                                endTime:$("#worksEndTime").val()
                            }
                        });
                        $("#search_zp").attr("stab","ttzpddbb");
                        f_findCountOrderWorks();
                    }else if(title=="项目订单报表"){
                        $('#ttrwdd').datagrid({
                            url:'${path}/orderReport/findOrderTaskReport.do',
                            method:'post',
                            queryParams:{
                                itemId:$("#itemId").val(),
                                beginTime:$("#finishBeginTime").val(),
                                endTime:$("#finishEndTime").val(),
                                itemOrderStatus:$("#itemOrderStatus").combobox("getValue"),
                                itemType:$("#itemType").combobox("getValue")
                            }
                        });
                        $("#search_rw").attr("stab","ttrwdd");

//                        f_findCountPlatformFinance();
                    }else if(title=="竞赛活动订单报表"){
                        $('#ttjshddd').datagrid({
                            url:'${path}/orderReport/findOrderRaceReport.do',
                            method:'post',
                            queryParams:{
                                raceId:$("#raceId").val(),
                                beginTime:$("#finishBeginTime2").val(),
                                endTime:$("#finishEndTime2").val(),
                                raceOrderStatus:$("#raceOrderStatus").combobox("getValue")
                            }
                        });
                        $("#search_jshd").attr("stab","ttjshddd");


                    }
                }
            });
        });

        // 根据项目订单ID显示阶段费用明细
        function f_showStage(item_order_id){

            //弹出窗口
            $('#dlg').dialog('open').dialog('setTitle','阶段费用明细');
            $('#dialogGrid1').datagrid({
                url:'${path}/orderReport/findOrderStageByItemOrderId.do',
                method:'post',
                queryParams:{
                    itemOrderId:item_order_id
                }
            });

        }
        // 根据任务ID显示增值服务费用明细
        function f_showAddvalue(order_task_id){

            //弹出窗口
            $('#dlg2').dialog('open').dialog('setTitle','增值服务费明细');
            $('#dialogGrid2').datagrid({
                url:'${path}/orderReport/findOrderItemAvByTaskOrderId.do',
                method:'post',
                queryParams:{
                    taskOrderId:order_task_id
                }
            });

        }

        // 根据项目ID查询手续费明细
        function f_showFee(item_order_id){

            //弹出窗口
            $('#dlg').dialog('open').dialog('setTitle','手续费明细');
            $('#dialogGrid1').datagrid({
                url:'${path}/orderReport/findOrderFeeByItemOrderId.do',
                method:'post',
                queryParams:{
                    itemOrderId:item_order_id
                }
            });

        }
        // 根据任务ID查询推广费明细
        function f_showPopur(order_task_id,contractId){

            //弹出窗口
            $('#dlg').dialog('open').dialog('setTitle','推广费明细');
            $('#dialogGrid1').datagrid({
                url:'${path}/orderReport/findOrderPopurByTaskOrderId.do',
                method:'post',
                queryParams:{
                    taskOrderId:order_task_id,
                    contractId:contractId
                }
            });

        }

        // 根据任务ID显示增值服务费用明细
        function f_showAddvalue_race(order_race_id){

            //弹出窗口
            $('#dlg2').dialog('open').dialog('setTitle','增值服务费明细');
            $('#dialogGrid2').datagrid({
                url:'${path}/orderReport/findOrderRaceAvByOrderRaceId.do',
                method:'post',
                queryParams:{
                    raceOrderId:order_race_id
                }
            });

        }
        // 根据任务ID显示增值服务费用明细
        function f_showWin_race(order_race_id){

            //弹出窗口
            $('#dlg3').dialog('open').dialog('setTitle','获奖明细');
            $('#dialogGrid3').datagrid({
                url:'${path}/orderReport/findOrderWinByOrderRaceId.do',
                method:'post',
                queryParams:{
                    raceOrderId:order_race_id
                }
            });

        }


        //作品订单报表--查询统计作品汇总数据
        function f_findCountOrderWorks(){
            $.post("${path}/orderReport/findCountOrderWorks.do",{
                worksId:$("#worksId").val(),
                beginTime:$("#worksBeginTime").val(),
                endTime:$("#worksEndTime").val()
            },function(data){
                if(data.errormsg == undefined){

                    $("#worksSumPrice").html(data.sumPriceMap.sumPrice);
                    $("#feeSumPrice").html(data.sumPriceMap.sumFee);

                }else{
                    alert(data.errormsg);
                }
            },"json");

        }
        //用户财务报表--查询统计用户财务汇总数据
        function f_findCountUserFinance(){

            $("#yhczSumPrice").html("0");
            $("#yhtxSumPrice").html("0");
            $.post("${path}/userFinance/findCountUserFinance.do",{
                itemId:$("#itemId").val(),
                beginTime:$("#finishBeginTime").val(),
                endTime:$("#finishEndTime").val(),
                itemOrderStatus:$("#itemOrderStatus").combobox("getValue"),
                itemType:$("#itemType").combobox("getValue")
            },function(data){
                if(data.errormsg == undefined){

                    for(var i = 0; i < data.sumPriceList.length;i++){

                        var bean = data.sumPriceList[i];

                        //充值
                        if(112101 == bean.type){

                            $("#yhczSumPrice").html(bean.sumMoney);

                        }
                        if(112106 == bean.type){//提现
                            $("#yhtxSumPrice").html(bean.sumMoney);
                        }


                    }



                }else{
                    alert(data.errormsg);
                }
            },"json");

        }


    </script>
</head>
<body class="easyui-layout">
<div region="center" style="padding:5px;" border="false">
    <div id="tabs" class="easyui-tabs" style="width:100%;height: 700px;">

        <div title="作品订单报表" style="padding:10px">
            <table id="ttzpddbb" class="easyui-datagrid"
                   data-options="singleSelect:true,collapsible:true,url:'${path}/orderReport/findOrderWorksReport.do',rownumbers: true,
       method:'post',toolbar:'#zpddbb',pagination:'true',fit:'true'">
                <thead>
                <tr>
                    <th data-options="field:'works_id',align:'center',width:180">作品编号</th>
                    <th data-options="field:'price',align:'center',width:180">作品金额</th>
                    <th data-options="field:'fee',align:'center',width:180">手续费</th>
                    <th data-options="field:'artistName',align:'center',width:180">艺术家账号</th>
                    <th data-options="field:'baileName',align:'center',width:180">委托方账号</th>
                    <th data-options="field:'finish_time',align:'center',width:180">完成时间</th>
                </tr>
                </thead>
            </table>
        </div>
        <div title="项目订单报表" style="padding:10px">
            <table id="ttrwdd" class="easyui-datagrid"
                   data-options="singleSelect:true,collapsible:true,url:null,rownumbers: true,
       method:'post',toolbar:'#rwddbb',pagination:'true',fit:'true',onLoadSuccess: loadSuccess">
                <thead frozen="true">
                <tr>
                    <th data-options="field:'item_id',align:'center',width:80">项目编号</th>
                    <th data-options="field:'taskPopur',align:'center',width:80">推广费</th>
                    <th data-options="field:'addvalue',align:'center',width:80,formatter: rowformatter_zzfw">增值服务费</th>
                    <th data-options="field:'presenter',align:'center',width:80">推荐者</th>
                    <th data-options="field:'create_time',align:'center',width:180">创建时间</th>
                </thead>
                </tr>
                <thead>
                <tr>
                    <th data-options="field:'item_contract_id',align:'center',width:80">合同编号</th>
                    <th data-options="field:'total_price',align:'center',width:80,formatter: rowformatter_jd">阶段总额</th>
                    <th data-options="field:'fee',align:'center',width:80,formatter: rowformatter_sxf">手续费</th>
                    <th data-options="field:'itemPopur',align:'center',width:80,formatter: rowformatter_tgf">推广费</th>
                    <th data-options="field:'type',align:'center',width:80">订单类型</th>
                    <th data-options="field:'baileName',align:'center',width:80">委托方</th>
                    <th data-options="field:'artistName',align:'center',width:80">艺术家</th>
                    <th data-options="field:'itemOrderStatus',align:'center',width:80">订单状态</th>
                    <th data-options="field:'itemCreateTime',align:'center',width:180">创建时间</th>
                    <th data-options="field:'finish_time',align:'center',width:180">完成时间</th>


                </tr>
                </thead>
            </table>
        </div>
        <div title="竞赛活动订单报表" style="padding:10px">
            <table id="ttjshddd" class="easyui-datagrid"
                   data-options="singleSelect:true,collapsible:true,url:null,rownumbers: true,
       method:'post',toolbar:'#jshd',pagination:'true',fit:'true'">
                <thead>
                <tr>
                    <th data-options="field:'race_id',align:'center',width:80">竞赛活动编号</th>
                    <th data-options="field:'popur',align:'center',width:80">推广费</th>
                    <th data-options="field:'addvalue',align:'center',width:80,formatter: rowformatter_race_zzfw">增值服务费</th>
                    <th data-options="field:'fee',align:'center',width:80 ">手续费</th>
                    <th data-options="field:'total_price',align:'center',width:80,formatter: rowformatter_race_win">总金额</th>
                    <th data-options="field:'presenter',align:'center',width:80">推荐者</th>
                    <th data-options="field:'publisher',align:'center',width:80">发布者</th>
                    <th data-options="field:'order_status',align:'center',width:80">订单状态</th>
                    <th data-options="field:'create_time',align:'center',width:180">创建时间</th>
                    <th data-options="field:'finish_time',align:'center',width:180">完成时间</th>


                </tr>
                </thead>
            </table>
        </div>

    </div>
</div>

<!--作品订单报表 头工具项-->
<div id="zpddbb" style="padding:2px 5px;">
    作品编号:<input class="easyui-textbox" name="worksId" id="worksId" style="width:110px">
    开始时间: <input placeholder="请选择开始时间"  type="text" id="worksBeginTime" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="Wdate" />
    结束时间: <input placeholder="请选择结束时间"  type="text" id="worksEndTime" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="Wdate" />
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="search_zp" stab="ttzpddbb">查找</a>
    <br/>
    <h3 style="color: #0000ff;">作品金额合计：<span id="worksSumPrice" style="color: red;">统计中...</span>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        手续费合计：<span id="feeSumPrice" style="color: red;">统计中...</span>
    </h3>
</div>
<!--项目订单报表 头工具项-->
<div id="rwddbb" style="padding:2px 5px;">
    项目编号:<input class="easyui-textbox" name="itemId" id="itemId" style="width:110px">
    完成开始时间: <input placeholder="请选择开始时间"  type="text" id="finishBeginTime" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="Wdate" />
    完成结束时间: <input placeholder="请选择结束时间"  type="text" id="finishEndTime" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="Wdate" />
    订单状态:
            <select class="easyui-combobox" data-options="editable:false" id="itemOrderStatus" style="width:110px">
                <option value="">所有</option>
                <option value="121101">未完成</option>
                <option value="121102">已完成</option>

            </select>
    订单类型:
            <select class="easyui-combobox" data-options="editable:false" id="itemType" style="width:110px">
                <option value="">所有</option>
                <option value="122101">定制服务订单</option>
                <option value="122102">任务合同订单</option>

            </select>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="search_rw" stab="ttrwdd">查找</a>

</div>
<!--竞赛活动订单报表 头工具项-->
<div id="jshd" style="padding:2px 5px;">
    竞赛活动编号:<input class="easyui-textbox" name="itemId" id="raceId" style="width:110px">
    完成开始时间: <input placeholder="请选择开始时间"  type="text" id="finishBeginTime2" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="Wdate" />
    完成结束时间: <input placeholder="请选择结束时间"  type="text" id="finishEndTime2" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="Wdate" />
    订单状态:
            <select class="easyui-combobox" data-options="editable:false" id="raceOrderStatus" style="width:110px">
                <option value="">所有</option>
                <option value="121101">未完成</option>
                <option value="121102">已完成</option>

            </select>

    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="search_jshd" stab="ttrwdd">查找</a>

</div>

<div id="dlg" class="easyui-dialog" style="width:600px;height:380px;padding:0px 0px"
     closed="true" >
    <div  style="height:340px">
        <table id="dialogGrid1" class="easyui-datagrid"
               data-options="singleSelect:true,collapsible:true,url:null,rownumbers: true,
       method:'post',toolbar:null,pagination:'true',fit:'true'">
            <thead>
            <tr>
                <th data-options="field:'stage_id',align:'center',width:80">阶段编号</th>
                <th data-options="field:'price',align:'center',width:80">金额</th>
                <th data-options="field:'finish_time',align:'center',width:180">完成时间</th>
                <th data-options="field:'order_status',align:'center',width:80">状态</th>
            </tr>
            </thead>
        </table>
    </div>

</div>
<div id="dlg2" class="easyui-dialog" style="width:600px;height:380px;padding:0px 0px"
     closed="true" >
    <div  style="height:340px">
        <table id="dialogGrid2" class="easyui-datagrid"
               data-options="singleSelect:true,collapsible:true,url:null,rownumbers: true,
       method:'post',toolbar:null,pagination:'true',fit:'true'">
            <thead>
            <tr>
                <th data-options="field:'addvalue_id',align:'center',width:80">增值服务编号</th>
                <th data-options="field:'price',align:'center',width:80">金额</th>
                <th data-options="field:'finish_time',align:'center',width:180">完成时间</th>
                <th data-options="field:'order_status',align:'center',width:80">状态</th>
            </tr>
            </thead>
        </table>
    </div>

</div>
<div id="dlg3" class="easyui-dialog" style="width:600px;height:380px;padding:0px 0px"
     closed="true" >
    <div  style="height:340px">
        <table id="dialogGrid3" class="easyui-datagrid"
               data-options="singleSelect:true,collapsible:true,url:null,rownumbers: true,
       method:'post',toolbar:null,pagination:'true',fit:'true'">
            <thead>
            <tr>
                <th data-options="field:'prize_id',align:'center',width:80">奖项编号</th>
                <th data-options="field:'money',align:'center',width:80">金额</th>
                <th data-options="field:'artistName',align:'center',width:80">获奖者</th>
                <th data-options="field:'finish_time',align:'center',width:180">完成时间</th>
                <th data-options="field:'win_status',align:'center',width:80">状态</th>
            </tr>
            </thead>
        </table>
    </div>

</div>

<script>

    function loadSuccess(data){

        var ss = new Array();
        var temp = new Array();

        data = data.rows;
        for(var i = 0; i < data.length;i++){


            var flag = false;
            for(var k in temp){
                if(temp[k] == data[i ].order_task_id){
                    flag = true;
                }
            }
            if(flag){
                continue;
            }
            temp.push(data[i ].order_task_id);
            var rowspan = 0;
            for(var j = 0; j < data.length; j++){

                if(data[i ].order_task_id == data[j].order_task_id){

                    rowspan ++;
                }
            }

            var xx = {index:i ,rowspan:rowspan};

            ss.push(xx);

            $('#ttrwdd').datagrid('mergeCells',{
                index:i ,
                field:'item_id',
                rowspan:rowspan
            });
            $('#ttrwdd').datagrid('mergeCells',{
                index:i ,
                field:'taskPopur',
                rowspan:rowspan
            });
            $('#ttrwdd').datagrid('mergeCells',{
                index:i ,
                field:'addvalue',
                rowspan:rowspan
            });
            $('#ttrwdd').datagrid('mergeCells',{
                index:i ,
                field:'presenter',
                rowspan:rowspan
            });
            $('#ttrwdd').datagrid('mergeCells',{
                index:i ,
                field:'create_time',
                rowspan:rowspan
            });
        }





    }

    //项目订单报表------增值服务费用
    function rowformatter_zzfw(value,row,index){


        if(value == undefined){
            value = "";
        }

        return  "<a href='javascript:void(0)' onclick=\"f_showAddvalue("+row.order_task_id+")\">"+value+"</a> ";
    }

    //项目订单报表------阶段总额
    function rowformatter_jd(value,row,index){


        if(value == undefined){
            value = "";
        }

        return  "<a href='javascript:void(0)' onclick=\"f_showStage("+row.item_order_id+")\">"+value+"</a> ";
    }
    //项目订单报表------手续费
    function rowformatter_sxf(value,row,index) {


        if (value == undefined) {
            value = "";
        }

        return  "<a href='javascript:void(0)' onclick=\"f_showFee(" + row.item_order_id + ")\">" + value + "</a> ";

    }
    //项目订单报表------推广费
    function rowformatter_tgf(value,row,index){


        if(value == undefined){
            value = "";
        }

        return  "<a href='javascript:void(0)' onclick=\"f_showPopur("+row.order_task_id+","+row.item_contract_id+")\">"+value+"</a> ";
    }


    //竞赛活动订单报表------增值服务费用
    function rowformatter_race_zzfw(value,row,index){


        if(value == undefined){
            value = "";
        }

        return  "<a href='javascript:void(0)' onclick=\"f_showAddvalue_race("+row.order_race_id+")\">"+value+"</a> ";
    }
    //竞赛活动订单报表------获奖者明细
    function rowformatter_race_win(value,row,index){


        if(value == undefined){
            value = "";
        }

        return  "<a href='javascript:void(0)' onclick=\"f_showWin_race("+row.order_race_id+")\">"+value+"</a> ";
    }

</script>
</body>
</html>
